/**
 * Created by no1 on 2015/6/30.
 */
'use strict';

/**
 * Module shop.
 */

let mongoose = require('mongoose');
//let shop = require('../schema/shop');

var extend = require('mongoose-schema-extend');
var ObjectId = mongoose.Schema.ObjectId;
var Mixed = mongoose.Schema.Types.Mixed;

var baseSchema = require('../schema/base').baseSchema
var Schema = mongoose.Schema;

//门店
var shop = baseSchema.extend({
  //商家id
  vendorid: {
    type: Number,
    ref: 'vendor',
    index: true
  },
  id: {
    type: Number,
    required: true,
    unique: true,
    index: true
  },

  district: [{
    name: String,
    code: Number,
    pCode: Number
  }],
  loc: {
    type: [Number],
    index: '2d'
  },

  //categories: [String], // 分类信息
  categories: [{
    name: String,
    pCode: Number,
    code: Number
  }], // 分类信息

  //商店的图片/tmp/1.jpg
  image: String,
  //机构负责人姓名
  shopKeeper: String,
  //机构负责人手机
  shopKeeperTel: String,
  //机构负责人邮箱
  shopKeeperEmail: String,
  //机构联系电话
  tel: [String],
  //地址
  address: String,
  //营业时间
  openTime: Number,
  closeTime: Number,

  eTotal: Number, //总评价得分
  eCount: Number, //评价次数
  eAverage: Number, //平均评价得分 eAverage=eTotal/eCount

  decorationGrade: Number, //环境评价
  serviceGrade: Number, //服务评价
  effectGrade: Number, // 效果评分

  // bitmapStatus 的每一位代表具体状态
  // bit0: 有无货物 0=否
  // bit1: 是否自营 0=否
  // bit2: 是否广告 0=否
  // bit3: 是否置顶 0=否
  //状态位
  bitmapStatus: {
    type: Number,
    default: 0
  },
  //优先级
  smartSort: {
    type: Number,
    default: 0
  },
  //1=开张,2=关闭,3=已删除
  //状态 0 删除 1 可用 2 删除审核中
  status: {
    type: Number,
    default: 1
  },

  //优惠  有特惠项目的商家列表标注
  discount: { // 0 没有 1 有
    type: Number,
    index: true
  },
  //预订  有预约项目的商家列表标注
  reservation: { // 0无 1有
    type: Number,
    index: true
  },

  //认证的商家 0没有认证 1 认证的
  authentication: Number,
  //数据来源 1管理后台 2爬虫 3美容日志
  source: {
    type: Number,
    index: true
  },
  //图文详情
  graphicDetails: String,

  //完整度 0 不完整 1完整
  integrity: Number,
  //提交时间
  submitTime: Date,
  //删除说明
  deleteDescription: String,
  //其他
  otherInfo: {
    type: Mixed
  }

});

shop.index({
  eTotal: 1
});


module.exports = mongoose.model('shop', shop);